package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@Slf4j
/**
 * 阿里云OSS配置类
 */
public class OssConfiguration {


    /**
     * 获取阿里云OSS客户端对象
     *
     * @return ossClient
     */
    @Bean
    @ConditionalOnMissingBean
    public AliOssUtil getOssClient(AliOssProperties aliOssProperties) {
        log.info("进入了获取阿里云oss客户端对象的方法,{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName()
                );
    }
}
